package com.logisticsmanagement.services;

import static com.logisticsmanagement.utils.GlobelValue.QUERY_NOT_FOUND;
import static com.logisticsmanagement.utils.GlobelValue.QUERY_NOT_FOUND_DESCRIPTON;
import static com.logisticsmanagement.utils.GlobelValue.QUERY_SUCCESS;
import static com.logisticsmanagement.utils.GlobelValue.QUERY_SUCCESS_DESCRIPTON;

import java.util.ArrayList;
import java.util.List;

import com.logisticsmanagement.dao.DeliveryStationDao;
import com.logisticsmanagement.domain.DeliveryStation;
import com.logisticsmanagement.domain.Indent;
import com.logisticsmanagement.vo.BaseResponse;
import com.logisticsmanagement.vo.VoCity;
import com.logisticsmanagement.vo.VoDeliveryStation;
import com.logisticsmanagement.vo.VoIndent;

public class DeliveryService {
	
	private DeliveryStationDao deliveryStationDao=new DeliveryStationDao();
	
	
	/**
	 * jundge delievryStation whether exists
	 * return true if exists
	 * @return
	 */
	public boolean DeliveryStationIsExit(int delievryStationID){
		DeliveryStation deliveryStation=deliveryStationDao.selectById(delievryStationID);
		if(deliveryStation==null){
			return false;
		}else{
			return true;
		}
	}
	
	/**
	 * get specified delievryStation by deliveryStationID
	 * @param deliveryStationID
	 * @return
	 */
	public BaseResponse<VoDeliveryStation> querydeliveryStationInfo(int deliveryStationID){
		DeliveryStation deliveryStation=new DeliveryStation();
		VoDeliveryStation voDeliveryStation=new VoDeliveryStation();
		List<VoDeliveryStation> listDeliveryStation=new ArrayList<VoDeliveryStation>();
		//set default value
		BaseResponse<VoDeliveryStation> baseResponseVoDeliveryStation=new BaseResponse<VoDeliveryStation>(QUERY_NOT_FOUND,
				QUERY_NOT_FOUND_DESCRIPTON,listDeliveryStation);
		deliveryStation=deliveryStationDao.selectById(deliveryStationID);
		voDeliveryStation.setCityID(deliveryStation.getCityID());
		voDeliveryStation.setDeliveryStationID(deliveryStation.getDeliveryStationID());
		voDeliveryStation.setStationName(deliveryStation.getStationName());
		voDeliveryStation.setArea(deliveryStation.getArea());
		
		listDeliveryStation.add(voDeliveryStation);

		baseResponseVoDeliveryStation.setResponseCode(QUERY_SUCCESS);
		baseResponseVoDeliveryStation.setResponseDescription(QUERY_SUCCESS_DESCRIPTON);
	
		return baseResponseVoDeliveryStation;		 
	}
	
	/**
	 * return ture if success to update deliveryStation
	 * @param newUser
	 * @return
	 */
	public boolean updateDeliveryStationInfo(DeliveryStation newDeliveryStation){
		
		return deliveryStationDao.update(newDeliveryStation);
	}
	
	/**
	 * return ture if success to add a delivery Station to database
	 */
	public void addDeliveryStation(DeliveryStation newDeliveryStation){
		
		deliveryStationDao.add(newDeliveryStation);
	}
	
	
	/**
	 * return ture if success to delete delievryCity from database
	 */
	public boolean deleteDelievryCity(int deliveryStationID){
		DeliveryStation deliveryStation=new DeliveryStation();
		deliveryStation=deliveryStationDao.selectById(deliveryStationID);
		//jundge whether could delete this object.
		//
		
		deliveryStation.setPrepareDelete(true);
		
		return deliveryStationDao.update(deliveryStation);
	}

}
